package xyz.syyrjx.blog.controller.tool;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import xyz.syyrjx.blog.service.ToolService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/tools")
public class ToolController {
    @Resource
    private ToolService service;

    @GetMapping("/shakeRice")
    public String shakeRice(HttpSession session){
        if(session.getAttribute("ifShakeRice") == null){
            session.setAttribute("ifShakeRice",1);
            service.updateView(1);
        }
        return "tools/shakeRice";
    }

    @RequestMapping("/minesweeper")
    public ModelAndView game2048Page(ModelAndView mv, HttpSession session) {
        if(session.getAttribute("ifMinesweeper") == null){
            session.setAttribute("ifMinesweeper",1);
            service.updateView(4);
        }
        mv.setViewName("/tools/minesweeper");
        return mv;
    }

    @RequestMapping("/ticTacToe")
    public ModelAndView ticTacToePage(ModelAndView mv, HttpSession session) {
        if(session.getAttribute("ifTicTacToe") == null){
            session.setAttribute("ifTicTacToe",1);
            service.updateView(5);
        }
        mv.setViewName("/tools/ticTacToe/head.html");
        return mv;
    }
}
